package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.WeekdaysAddDTO;
import org.jsola.hr.dto.WeekdaysUpdateDTO;
import org.jsola.hr.entity.WeekdaysDO;
import org.jsola.hr.query.WeekdaysQuery;
import org.jsola.hr.service.IWeekdaysService;
import org.jsola.hr.vo.WeekdaysVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 工作日历表
 *
 * @author zhr
 */
@Component
public class WeekdaysTestHelper extends BaseTestHelper {
    
    @Autowired
    private IWeekdaysService weekdaysService;

    /**
     * 生成add测试数据
     * @return WeekdaysAddDTO
     */
    public WeekdaysAddDTO getWeekdaysAddDTO(){
        WeekdaysAddDTO weekdaysAddDTO = new WeekdaysAddDTO();
        weekdaysAddDTO.setHolidayDate((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        weekdaysAddDTO.setWeekday(getRandomValue("varchar",32));
        weekdaysAddDTO.setHoliday(getRandomValue("varchar",32));
        weekdaysAddDTO.setStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        return weekdaysAddDTO;
    }


    /**
     * 生成update测试数据
     * @return WeekdaysUpdateDTO
     */
    public WeekdaysUpdateDTO getWeekdaysUpdateDTO(WeekdaysVO weekdaysVO){
        return weekdaysService.selectDOById(weekdaysVO.getId(), SITE_ID).to(WeekdaysUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return WeekdaysQuery
     */
    public WeekdaysQuery getWeekdaysQuery() {
        WeekdaysQuery weekdaysQuery = new WeekdaysQuery();
        List<WeekdaysDO> weekdaysDOList = weekdaysService.list(new WeekdaysDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(weekdaysDOList)) {
            WeekdaysDO weekdaysDO = weekdaysDOList.get(0);
            weekdaysQuery = weekdaysDO.to(WeekdaysQuery.class);
            if (weekdaysDO.getHolidayDate() != null) {
                weekdaysQuery.setHolidayDateStart(DateKit.getBeforeDay(weekdaysDO.getHolidayDate(),-1));
                weekdaysQuery.setHolidayDateEnd(DateKit.getBeforeDay(weekdaysDO.getHolidayDate(),1));
            }
        }
        return weekdaysQuery;
    }

    /**
     * 保存示例
     * @return WeekdaysVO
     */
    public WeekdaysVO saveWeekdaysExample(){
        WeekdaysAddDTO addDTO = this.getWeekdaysAddDTO();
        WeekdaysVO weekdaysVO = weekdaysService.save(addDTO,buildTokenUser());
        return weekdaysVO;
    }


}

